package cn.houserent.service.impl;

import java.util.List;

import org.hibernate.Transaction;

import cn.houserent.dao.HibernateUtil;
import cn.houserent.dao.UserDao;
import cn.houserent.dao.impl.UserDaoImpl;
import cn.houserent.entity.Users;
import cn.houserent.service.UserBiz;

public class UserBizImpl implements UserBiz{

	private UserDao userDao = new UserDaoImpl();
	
	@Override
	public void register(Users user) {
		Transaction tx =null;
		try{
			tx = HibernateUtil.currentSession().beginTransaction();
			userDao.insert(user);
			tx.commit();
		}catch (Exception e) {
			if(tx != null){
				tx.rollback();
			}
		}
	}

	@Override
	public Users signIn(Users user) {
		Transaction tx =null;
		Users users = null;
		try{
			tx = HibernateUtil.currentSession().beginTransaction();
			users=userDao.getUsers(user).get(0);
			tx.commit();
		}catch (Exception e) {
			if(tx != null){
				tx.rollback();
			}
		}
		return users;
	}

}
